//
//  BkShopCarBottomView.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/11.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "BkShopCarBottomView.h"
@interface BkShopCarBottomView()
@property (nonatomic,strong) UIButton *commitBtn;
@end

@implementation BkShopCarBottomView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, TSScreenWidth, TSScaleW(55));
        _allSelecBtn = [TSWLTools allocButtonTitle:@"全选" font:systemFont(TSScaleW(12)) textColor:kMainTxtColor image:[UIImage imageNamed:@"weixuanzhong"] frame:CGRectMake(0, 0, TSScaleW(80), self.height) sel:@selector(allSelecBtnAction:) taget:self];
        [_allSelecBtn setImage:[UIImage imageNamed:@"xuanzhong"] forState:(UIControlStateSelected)];
        [_allSelecBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,TSScaleW(10), 0, 0)];
        _totalLabel = [TSWLTools allocLabel:@"总计：￥0.00" font:systemFont(TSScaleW(15)) textColor:kMainTxtColor frame:CGRectMake(_allSelecBtn.right, 0, TSScaleW(150), self.height) textAlignment:(NSTextAlignmentRight)];
        [self addSubview:self.commitBtn];
        [self addSubview:self.allSelecBtn];
        [self addSubview:self.totalLabel];
        _type = @"1";
    }
    return self;
}
-(void)allSelecBtnAction:(UIButton *)sender
{
    sender.selected = !sender.selected;
    !self.allSelctBlock?:self.allSelctBlock(sender.selected);
}
-(UIButton *)commitBtn{
    if (!_commitBtn) {
        _commitBtn = [TSWLTools allocButtonTitle:@"去结算（0)" font:systemFont(TSScaleW(15)) textColor:kWhiteColor image:nil frame:CGRectMake(TSScaleW(11), TSScaleW(10) , TSScaleW(114), TSScaleW(35)) sel:@selector(commentAction:) taget:self];
        _commitBtn.backgroundColor = kGreenColor;
        _commitBtn.cornerRadius = _commitBtn.height/2.f;
        _commitBtn.right = TSScreenWidth - TSScaleW(12);
    }
    return _commitBtn;
}
-(void)commentAction:(UIButton *)sender
{
    if (_type.integerValue == 1) {
        !self.gotoBuyBlock?:self.gotoBuyBlock();
    }
    if (_type.integerValue == 2) {
        !self.gotoDeleteBlock?:self.gotoDeleteBlock();
    }
}
-(void)setType:(NSString *)type
{
    _type = type;
    if (_type.integerValue == 1) {
        ///结算
        NSString *message = [NSString stringWithFormat:@"去结算（%ld）",_selectCount];
        [_commitBtn setBackgroundColor:kGreenColor];
        [_commitBtn setTitle:message forState:(UIControlStateNormal)];
    }
    if (_type.integerValue == 2) {
        ///删除
        NSString *message = [NSString stringWithFormat:@"删除"];
        [_commitBtn setBackgroundColor:kRedColor];
        [_commitBtn setTitle:message forState:(UIControlStateNormal)];
    }
}
-(void)setSelectCount:(NSInteger)selectCount{
    _selectCount = selectCount;
    if (self.type.integerValue == 1) {
        NSString *message = [NSString stringWithFormat:@"去结算（%ld）",_selectCount];
        [_commitBtn setTitle:message forState:(UIControlStateNormal)];
    }
}
@end
